package com.acargil.sudoku.model;

import com.acargil.sudoku.model.algorithm.generation.IGenerator;
import com.acargil.sudoku.model.algorithm.generation.PuzzleGeneratorFactory;
import com.acargil.sudoku.model.algorithm.solution.ISolver;
import com.acargil.sudoku.model.algorithm.solution.PuzzleSolverFactory;


/**
 * This abstract class holds the required methods that must be implemented by
 * each STANDARD SUDOKU model.
 * 
 * @author oguzhan
 */
public abstract class StandardSudokuEngine implements IStandardSudokuEngine {

	private static final long serialVersionUID = 1L;
	
	private PuzzleGenerationAlgorithm defaultGenerationAlgorithm;
	private PuzzleSolvingAlgorithm defaultSolvingAlgorithm;
	
	public StandardSudokuEngine() {
		this.defaultGenerationAlgorithm = PuzzleGenerationAlgorithm.BASIC_ALGORITHM;
		this.defaultSolvingAlgorithm = PuzzleSolvingAlgorithm.BASIC_ALGORITHM;
	}

	@Override
	public int[][] solve() {
		PuzzleSolvingAlgorithm algorithm = getDefaultSolvingAlgorithm();
		return solve(algorithm);
	}
	
	@Override
	public int[][] generatePuzzle() {
		PuzzleGenerationAlgorithm algorithm= getDefaultGenerationAlgorithm();
		return generatePuzzle(algorithm);
	}

	@Override
	public int[][] solve(PuzzleSolvingAlgorithm algorithm) {
		ISolver solver = PuzzleSolverFactory.createSolver(algorithm);
		return solver.solve(getAllCellValues());
	}

	@Override
	public int[][] generatePuzzle(PuzzleGenerationAlgorithm algorithm) {
		IGenerator generator = PuzzleGeneratorFactory.createGenerator(algorithm);
		return generator.generate();
	}

	public PuzzleGenerationAlgorithm getDefaultGenerationAlgorithm() {
		return defaultGenerationAlgorithm;
	}

	public void setDefaultGenerationAlgorithm(PuzzleGenerationAlgorithm defaultGenerationAlgorithm) {
		this.defaultGenerationAlgorithm = defaultGenerationAlgorithm;
	}

	public PuzzleSolvingAlgorithm getDefaultSolvingAlgorithm() {
		return defaultSolvingAlgorithm;
	}

	public void setDefaultSolvingAlgorithm(PuzzleSolvingAlgorithm defaultSolvingAlgorithm) {
		this.defaultSolvingAlgorithm = defaultSolvingAlgorithm;
	}

	
}
